home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / c / GED_Scripts.lha / GED_Scripts / NewAutodoc.c < prev    next >
C/C++ Source or Header  |  1999-02-24  |  4KB  |  171 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for Autodoc nodes. This handler simply looks for
  4.   formfeeds and therefore won't work with all Autodocs (Commodore's Autodocs
  5.   are handled properly).
  6.  
  7.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  8.   code and no library calls permitted. We have to put string constants into
  9.   the code segment (DICE compiler: option -ms1).
  10.  
  11.   DICE:
  12.  
  13.   dcc autodocslow.c -// -l0 -md -mRR -o golded:etc/scanner/autodocslow
  14.  
  15.   ------------------------------------------------------------------------------
  16. */
  17.  
  18. #include <exec/types.h>
  19.  
  20. #define REG(x) register __##x
  21. #define FORMFEED 12
  22.  
  23. ULONG ScanHandlerGuide(REG(d0) ULONG len, REG(a0) char **text, REG(a1) ULONG *line)
  24. {
  25.     const char version[] = "$VER: NewADoc 1.1 (24.02.99)";
  26.  
  27.     static UBYTE buffer[255];
  28.     static ULONG inbuffer;
  29.  
  30.     UBYTE *next;
  31.     ULONG  length;
  32.  
  33.     // buffer length for later use
  34.  
  35.     length = len;
  36.  
  37.     // clear "last result" buffer if we start parsing a new document
  38.  
  39.     if (line == 0)
  40.         *buffer = 0;
  41.  
  42.  
  43.     if (**text == FORMFEED) {
  44.  
  45.         // look for beginning of header string (e.g. "Dos.Library/Open")
  46.  
  47.         while (len && (**text <= ' ')) {
  48.  
  49.             ++*text;
  50.             --len;
  51.         }
  52.  
  53.         // ignore first part of header string
  54.  
  55.         while (len && (**text != '/')) {
  56.  
  57.             ++*text;
  58.             len--;
  59.         }
  60.  
  61.         // extract node name
  62.  
  63.         if (len) {
  64.  
  65.             ULONG letters;
  66.  
  67.             ++*text;
  68.             --len;
  69.  
  70.             for (letters = 0; len && ((*text)[letters] >= '.'); --len)
  71.                 ++letters;
  72.  
  73.             if (letters)
  74.                {
  75.                   // buffer result
  76.  
  77.                   buffer[letters] = 0;
  78.  
  79.                   len = letters;
  80.  
  81.                   while (len--)
  82.                      buffer[len] = (*text)[len];
  83.  
  84.                   inbuffer = letters;
  85.  
  86.                   return(letters);
  87.                }
  88.             else
  89.                return FALSE;
  90.         }
  91.     }
  92.  
  93.  
  94.     // did one of the previous lines produce a result ?
  95.  
  96.     if (*buffer) {
  97.  
  98.         next = *text;
  99.  
  100.         // look for "alternative version" mentioned in the text
  101.  
  102.         while (length) {
  103.  
  104.             // skip white space
  105.  
  106.             while (length && (*next < 'A')) {
  107.  
  108.                 --length;
  109.  
  110.                 ++next;
  111.             }
  112.  
  113.             // check next word
  114.  
  115.             if (length) {
  116.  
  117.                 ULONG keylen;
  118.  
  119.                 // set (possible) result string
  120.  
  121.                 *text = next;
  122.  
  123.                 // determine length of next word
  124.  
  125.                 for (keylen = 0; length && (*next >= 'A'); ++next) {
  126.  
  127.                     ++keylen;
  128.  
  129.                     --length;
  130.                 }
  131.  
  132.                 // close match found ?
  133.  
  134.                 if (**text == *buffer) {
  135.  
  136.                     // only last letter may differ; eg. DrawBevelBox vs. DrawBevelBoxA
  137.  
  138.                     if ((keylen == (inbuffer + 1)) || (keylen == (inbuffer - 1))) {
  139.  
  140.                         ULONG compare = (keylen < inbuffer) ? keylen : inbuffer;
  141.  
  142.                         // does one of both end with 'A'?
  143.  
  144.                         if ((*text)[compare] != 'A' && buffer[compare] != 'A')
  145.                            return FALSE;
  146.  
  147.                         while (compare--) {
  148.  
  149.                             if ((*text)[compare] != buffer[compare])
  150.                                 break;
  151.  
  152.                             else if (compare == 0) {
  153.  
  154.                                 // stop searching for alternative versions
  155.  
  156.                                 *buffer = 0;
  157.  
  158.                                 // return result
  159.  
  160.                                 return(keylen);
  161.                             }
  162.                         }
  163.                     }
  164.                 }
  165.             }
  166.         }
  167.     }
  168.  
  169.     return(FALSE);
  170. }
  171.